
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <#include "../common/header.ftl">
</head>
<script>
    function moveAll(srcEl,targetEl) {
        //console.log($(".allRoles option"));
        $("."+srcEl+" option").appendTo($("."+targetEl))
    }

    function moveSelected(srcEl,targetEl) {
        //console.log($(".allRoles option"));
        $("."+srcEl+" option:selected").appendTo($("."+targetEl))
    }

    $(function () {

        var selRoles = $(".selfRoles option")

        var allRoles = $(".allRoles option")

        var ids = $.map(selRoles,function (option) {
            return option.value;
        })

        $.each(allRoles,function (index,option) {
            if($.inArray(option.value,ids)>=0){
                option.remove()
            }
        })
        $("#btn_submit").click(function () {
            $(".selfRoles option").prop("selected",true)
            $("#editForm").submit();
        })

    })
</script>
<body>

<div class="container " style="margin-top: 20px">
    <#include "../common/top.ftl">
    <div class="row">
        <div class="col-sm-3">
            <#include "../common/menu.ftl">
        </div>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">角色编辑</h1>
                </div>
            </div>
            <div class="row col-sm-10">
                <form class="form-horizontal" action="/role/saveOrUpdate.do" method="post" id="editForm">
                    <input type="hidden" value="${(entity.id)!}" name="id">
                    <div class="form-group" >
                        <label for="name" class="col-sm-2 control-label">角色名称：</label>
                        <div class="col-sm-6">
                        <input type="text" class="form-control" id="name" name="name" value="${(entity.name)!}" placeholder="请输入角色名称">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="sn" class="col-sm-2 control-label">角色编号：</label>
                        <div class="col-sm-6">
                        <input type="text" class="form-control" id="sn" name="sn" value="${(entity.sn)!}" placeholder="请输入角色编号">
                        </div>
                    </div>
                    <div class="form-group" id="role">
                        <div>
                            <label for="role" class="control-label" style="margin-left: 60px">權限：</label>
                        </div>
                        <div class="row" style="margin-top: 10px">
                            <div class="col-sm-4 col-sm-offset-1">
                                <select multiple class="form-control allRoles" size="15">
                                    <#list allExpression as r>
                                        <option value="${r.id}" >${r.name}</option>
                                    </#list>
                                </select>
                            </div>

                            <div class="col-sm-2" style="margin-top: 60px;" align="center">
                                <div >
                                    <a type="button" class="btn btn-info  "  style="margin-top: 10px"
                                       onclick="moveSelected('allRoles', 'selfRoles')">&nbsp;&gt;&nbsp;</a>
                                    <br>
                                    <a type="button" class="btn btn-info " style="margin-top: 10px"
                                       onclick="moveSelected('selfRoles', 'allRoles')">&nbsp;&lt;&nbsp;</a>
                                    <br>
                                    <a type="button" class="btn btn-info " style="margin-top: 10px"
                                       onclick="moveAll('allRoles', 'selfRoles')">&gt;&gt;</a>
                                    <br>
                                    <a type="button" class="btn btn-info " style="margin-top: 10px"
                                       onclick="moveAll('selfRoles', 'allRoles')">&lt;&lt;</a>
                                </div>
                            </div>

                            <div class="col-sm-4">
                                <select multiple class="form-control selfRoles" size="15" name="ids">
                                    <#list (entity.list)! as r>
                                        <option value="${r.id}" >${r.name}</option>
                                    </#list>
                                </select>
                            </div>
                        </div>
                    </div>



                    <div class="form-group">
                        <div class="col-sm-offset-1 col-sm-6">
                            <button id="btn_submit" class="btn btn-default">保存</button>
                            <button type="reset" class="btn btn-default">重置</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
</body>
</html>